#!/usr/bin/env python

"""
Mind 2 Music
Copyright (C) 2010  Sytze K. Zeijlmaker

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
"""

import pygtk
pygtk.require("2.0")
import gobject
import gtk
import gtk.glade
from EditView import * 
import Composition
import threading

class m2m:
	def __init__(self):
		self.gui=gtk.glade.XML("m2m.glade","mainwindow")
		
		self.window=self.gui.get_widget("mainwindow")
		
		# Make Editview
		self.editview=EditView(self)
		self.editview.IN=Composition.n
		self.editview.OUT=Composition.n
		self.gui.get_widget("hbox").pack_end(self.editview)
		
		# Redirecting signals
		dick={
			"on_insert"   :(self.editview.Insert,self.editview),
			"on_duplicate":(self.editview.Duplicate,self.editview),
			"on_delete"   :(self.editview.Remove,self.editview),
			"move_right"  :(self.editview.EditEvent,self.editview,1,0,0),
			"move_left"   :(self.editview.EditEvent,self.editview,-1,0,0),
			"move_up"     :(self.editview.EditEvent,self.editview,0,1,0),
			"move_down"   :(self.editview.EditEvent,self.editview,0,-1,0),
			"make_longer" :(self.editview.EditEvent,self.editview,0,0,1),
			"make_shorter":(self.editview.EditEvent,self.editview,0,0,-1),
			"nav_right"   :(self.editview.NavEvent,self.editview,1,0),
			"nav_left"    :(self.editview.NavEvent,self.editview,-1,0),
			"nav_up"      :(self.editview.NavEvent,self.editview,0,1),
			"nav_down"    :(self.editview.NavEvent,self.editview,0,-1)
		}
		self.gui.signal_autoconnect(dick)
		
		self.window.connect("key-press-event",self.editview.key)
		self.window.connect("destroy-event",self.quit)
		self.window.connect("destroy",self.boomheadshot)
		
		self.window.show_all()
		
	def update_status(self):
		bla=""
	
	def quit(self, widget, event, data=None):
		# Change FALSE to TRUE and the main window will not be destroyed
		# with a "delete_event".
		return False
	
	def boomheadshot(self, widget, data=None):
		gtk.main_quit()
	
	def main(self):
		gtk.main()

gobject.threads_init()

if __name__=="__main__":
	app = m2m()
	app.main()

